layui.define(['index', 'form', 'laydate'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let laydate = layui.laydate;

    let startDate = new Date();
    if (json.startTime !== null && json.startTime !== "" && json.startTime !== undefined){
        startDate = json.startTime;
    }

    zmnLayUtil.layFormVerify(form);
    laydate.render({
        elem: '#start_time',
        type: "date",
        value: startDate
    });

    laydate.render({
        elem: '#end_time',
        type: "date",
        value: json.endTime
    });

    form.on('submit(staff-setIp-form-submit)', function (obj) {
        let endTime = $("#end_time").val();
        let startTime = $("#start_time").val();
        if (endTime === undefined || endTime === "" || endTime === null) {
            layer.msg("结束时间不能为空!", {"icon": 2});
            return false;
        }
        if (startTime > endTime) {
            layer.msg("开始时间不能大于结束时间!", {"icon": 2});
            return false;
        }
        let data = {
            "staffName": json.staffName,
            "endTime": endTime,
            "startTime":startTime
        };
        $.post("/mc/staff/openIpLogin.action", data, function (res) {
            if (res.status === 200) {
                zmnLayUtil.closeThisIframeMsg(parent, res.message, "");
            } else {
                layer.msg(res.message, {"icon": 2});
            }
        });
        return false;
    });

    //点击取消
    $(document).on('click', '#cancel', function () {
        zmnLayUtil.closeThisIframe(parent);
    });

    //对外暴露的接口
    exports('art_staffpermitdata_openIpLoginDateList', {});
});
